<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a><cite>活动管理</cite></a>
    <a><cite>创建邀请活动</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body" style="padding-top: 40px;">
      <div carousel-item>
        <div>
          <form class="layui-form" style="margin: 50px auto;max-width: 700px;">
            <script type="text/html" template lay-url="agent-admin/invites/{{d.params.id}}" lay-done="layui.data.done(d.data)">
              {{# let data = {}; }}
              <div class="layui-form-item">
                <label class="layui-form-label">活动名称</label>
                <div class="layui-input-inline" style="width: 300px">
                  <input name="name" type="text" lay-verify="required" class="layui-input" value="{{d.data.name || ''}}"/>
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">开始时间</label>
                  <div class="layui-input-inline">
                    <input type="text" id="start_time" class="layui-input" name="start_time" placeholder="请选择开始时间"
                           autocomplete="off" value="{{d.data.start_time || ''}}">
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">结束时间</label>
                  <div class="layui-input-inline">
                    <input type="text" id="end_time" class="layui-input" name="end_time" placeholder="请选择结束时间"
                           autocomplete="off" value="{{d.data.end_time || ''}}">
                  </div>
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">榜单位数</label>
                  <div class="layui-input-inline">
                    <input type="text" class="layui-input" lay-verify="required" name="ranking_num"
                           value="{{d.data.ranking_num || ''}}">
                  </div>
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label form-required" id="logo_label">海报封面</label>
                <div class="layui-input-block">
                  <div id="image_url"></div>
                </div>
              </div>
              <!--<div class="layui-form-item">
                <div class="layui-input-inline">
                  <a class="layui-btn" lay-submit lay-filter="submit_invite">保存</a>
                  <input type="button" layadmin-event="back" value="返回" class="layui-btn layui-btn-primary">
                </div>
              </div>-->
              <div class="layui-card-body layui-row layui-col-space10">
                <div class="layui-col-md6">
                  <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline">
                      <a class="layui-btn" lay-submit lay-filter="submit_invite">保存</a>
                    </div>
                  </div>
                </div>
              </div>
            </script>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
  layui.data.done = function () {
    console.log()
    layui.use(['step', 'fox_upload', 'laydate'], function () {
      let $ = layui.$
        , form = layui.form
        , admin = layui.admin
        , fox_upload = layui.fox_upload
        , laydate = layui.laydate

      let form_data = {}

      form.render()

      //# STEP 1
      //日历初始化
      laydate.render({
        elem: '#start_time'
        , type: 'datetime'
      });
      laydate.render({
        elem: '#end_time'
        , type: 'datetime'
      });

      //上传控件初始化
      fox_upload.render({
        elem: '#image_url'
        , url: 'agent-admin/products/image'
        , headers: {
          Authorization: admin.getAccessToken('Bearer')
        }
        , text: '点击上传'
        , name: 'img_url'
      })

      // 创建邀请活动
      form.on('submit(submit_invite)', function (d) {
        admin.post('agent-admin/invites/create', d.field, function () {
          history.back()
        })
        return false;
      })
    })
  }
</script>

